package ltd.newbee.mall.product.service.impl;

import ltd.newbee.mall.product.entity.Product;
import ltd.newbee.mall.product.mapper.ProductMapper;
import ltd.newbee.mall.product.service.ProductService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public Product findById(Long id) {
        return productMapper.findById(id);
    }

    @Override
    public List<Product> findPage(int page, int size, String keyword) {
        int offset = Math.max(page - 1, 0) * Math.max(size, 1);
        return productMapper.findPage(offset, size, keyword == null ? null : keyword.trim());
    }

    @Override
    public List<Product> findHot(int limit) {
        return productMapper.findHot(Math.max(limit, 1));
    }

    @Override
    public List<Product> findNew(int limit) {
        return productMapper.findNew(Math.max(limit, 1));
    }

    @Override
    public List<Product> findRecommend(int limit) {
        return productMapper.findRecommend(Math.max(limit, 1));
    }
}


